/**
 * Created by IntelliJ IDEA.
 * User: mstine
 * Date: Mar 20, 2008
 * Time: 3:52:08 PM
 * To change this template use File | Settings | File Templates.
 */
Integer.metaClass.rand = {->
    def r = new Random()
    return r.nextInt(delegate.intValue())
}

15.times {println 10.rand()}

//Slightly more advanced example

String.metaClass.get = {->
    return delegate.toURL().text
}

String.metaClass.get = {String queryString ->
    def url = delegate + "?" + queryString
    return url.get()
}

String.metaClass.get = {Map params ->
    def list = []
    params.each {k, v -> list << "$k=" + URLEncoder.encode(v)}
    def url = delegate + "?" + list.join("&")
    return url.get()
}

println "http://www.google.com/".get()
println "http://search.yahoo.com/search".get("p=groovy")

def params = [:]
params.n = "10"
params.vl = "lang_eng"
params.p = "groovy"
println "http://search.yahoo.com/search".get(params)

//GO BACK TO SLIDES